﻿using System;
using System.Xml.Linq;
using System.Collections.Generic;
using MediaPortal.Dialogs;
using MediaPortal.GUI.Library;
using ClrExtensions.Net.Rest;
using MediaPortal.GUI.Library;

namespace MyNetflix2
{
    public class Person : Queue
    {
        List<string> _actorName = new List<string>();
        List<string> _actorLink = new List<string>();

        public List<string> ActorName
        {
            get { return _actorName; }
        }
        public List<string> ActorLink
        {
            get { return _actorLink; }
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="user"></param>
        public Person(User user)
            : base(user)
        {}

        /// <summary>
        /// Refresh the Disc Queue
        /// </summary>
        /// <param name="resource"></param>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        public override List<QueueItem> Refresh(string person)
        {
            //--------------------------------------------------------------------------------
            // Set up the Rest call to get the Disc Queue
            //--------------------------------------------------------------------------------
            RestCall request = RestCalls.GetCatalogPeople(person, StartIndex, EndIndex);

            try
            {
                //--------------------------------------------------------------------------------
                // Get the Disc Queue from Netflix
                //--------------------------------------------------------------------------------
                string xml = base.NetFlixUser.NetflixConnection.RequestResource(request, base.NetFlixUser.Token);

                //--------------------------------------------------------------------------------
                // Parse to Linq
                //--------------------------------------------------------------------------------
                XElement root = XElement.Parse(xml);
 

                //--------------------------------------------------------------------------------
                // Add the elements to the QueueItems class
                //--------------------------------------------------------------------------------
                foreach (XElement node in root.Elements("person"))
                {
                    //XDocument doc = XDocument.Load(

                    //_actorName.Add(node.Element("name").Value);

                    //IEnumerable<XElement> address = from el in node.Element("OpenSearchDescription").Element("movies").Element("movie").Element("images").Elements("image")
                    //                                where (string)el.Attribute("type") == "backdrop" && (string)el.Attribute("size") == "poster"
                    //                                select el;

                }

                return SortByYear();
            }
            catch (Exception ex)
            {
                Log.Error("My NetFlix - Person:Refresh(): Error - " + ex.Message);
                return null;
            }
        }
    }
}
